﻿using System;
using System.Collections.Generic;
using AutoMapper;
using Navigant.DataContracts;
using Navigant.Infrastructure.Cases;
using Navigant.Infrastructure.ClientPortals;
using Navigant.ServiceInterfaces;

namespace Navigant.WebServices
{
    public class ClientPortalService : IClientPortalService
    {
        #region IClientPortalService Members

        public PortalContract GetPortal(Guid clientPortalId)
        {
            IClientPortal clientPortal = Navigant.Model.ClientPortals.ClientPortalService.GetClientPortalBy(clientPortalId);
            PortalContract portal = Mapper.Map<IClientPortal, PortalContract>(clientPortal);
            return portal;
        }

        public List<CaseContract> GetCases(Guid clientPortalId)
        {
            List<CaseContract> caseContracts = new List<CaseContract>();
            IList<ICase> caseSites = Navigant.Model.ClientPortals.ClientPortalService.FindAllCases(clientPortalId);
            foreach (ICase caseSite in caseSites)
            {
                caseContracts.Add(Mapper.Map<ICase, CaseContract>(caseSite));
            }
            return caseContracts;
        }

        public List<CaseContract> GetCasesByCategory(Guid clientPortalId, string siteDirectoryName, string categoryName, string categoryValue)
        {
            List<CaseContract> caseContracts = new List<CaseContract>();
            IList<ICase> caseSites = Navigant.Model.ClientPortals.ClientPortalService.FindAllCases(clientPortalId, 
                siteDirectoryName, categoryName, categoryValue);
            foreach (ICase caseSite in caseSites)
            {
                caseContracts.Add(Mapper.Map<ICase, CaseContract>(caseSite));
            }
            return caseContracts;
        }

        public SiteDirectoryCategoriesContract GetSiteDirectoryCategories(Guid clientPortalId, string siteDirectoryName, string categoryName)
        {
            IList<string> categories = Navigant.Model.ClientPortals.ClientPortalService.GetCaseSiteCategories(clientPortalId, 
                siteDirectoryName, categoryName);
            string defaultCategory = Navigant.Model.ClientPortals.ClientPortalService.GetDefaultCaseSiteCategory(clientPortalId, 
                siteDirectoryName, categoryName);
            return new SiteDirectoryCategoriesContract()
            {
                Categories = new List<string>(categories),
                DefaultCategoryValue = defaultCategory
            };
        }

        #endregion
    }
}
